package io.web.api.auto;

import io.web.api.ApiClient;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(ApiClient.class)
@EnableConfigurationProperties(ApiProperties.class)
@AllArgsConstructor
public class ApiClientAutoConfiguration {

    private final ApiProperties apiProperties;

    @Bean
    @ConditionalOnMissingBean(ApiClient.class)
    public ApiClient apiClient() {
        return new ApiClient(apiProperties.getUrl());
    }
}
